var toastr = {
    error:function(msg){
        if(app && app.$toast){
            app.$toast.error(msg)
        }
    },
    success:function (msg) {
        if(app && app.$toast){
            app.$toast.success(msg)
        }
    }
}
var moment = dayjs;
var isFunction = function isFunction(obj) {

    // Support: Chrome <=57, Firefox <=52
    // In some browsers, typeof returns "function" for HTML <object> elements
    // (i.e., `typeof document.createElement( "object" ) === "function"`).
    // We don't want to classify *any* DOM node as a function.
    return typeof obj === "function" && typeof obj.nodeType !== "number";
};
var rreturn = /\r/g;
jQuery.fn.extend({
    val: function(value) {
        var hooks, ret, valueIsFunction,
            elem = this[0];
        if(value != null && value != 'undefined'){
            var selector = $(this).selector;
            if(selector.indexOf("dcqtech_data=") != -1){
                let id =  selector.split("=")[1];
                id = id.substring(1,id.length-2)
                console.log(id);
                app.vModel[id] = value;
                // for (let i = 0; i < app.widgets; i++) {
                //     let widget = app.widgets[i]
                //     if(widget.id == id){
                //         widget.value = value
                //         break;
                //     }
                // }
                return;
            }
        }



        if (!arguments.length) {
            if (elem) {
                hooks = jQuery.valHooks[elem.type] ||
                    jQuery.valHooks[elem.nodeName.toLowerCase()];

                if (hooks &&
                    "get" in hooks &&
                    (ret = hooks.get(elem, "value")) !== undefined
                ) {
                    return ret;
                }

                ret = elem.value;

                // Handle most common string cases
                if (typeof ret === "string") {
                    return ret.replace(rreturn, "");
                }

                // Handle cases where value is null/undef or number
                return ret == null ? "" : ret;
            }

            return;
        }

        valueIsFunction = isFunction(value);

        return this.each(function(i) {
            var val;

            if (this.nodeType !== 1) {
                return;
            }

            if (valueIsFunction) {
                val = value.call(this, i, jQuery(this).val());
            } else {
                val = value;
            }

            // Treat null/undefined as ""; convert numbers to string
            if (val == null) {
                val = "";

            } else if (typeof val === "number") {
                val += "";

            } else if (Array.isArray(val)) {
                val = jQuery.map(val, function(value) {
                    return value == null ? "" : value + "";
                });
            }

            hooks = jQuery.valHooks[this.type] || jQuery.valHooks[this.nodeName.toLowerCase()];

            // If set returns undefined, fall back to normal setting
            if (!hooks || !("set" in hooks) || hooks.set(this, val, "value") === undefined) {
                this.value = val;
            }
        });
    }
});
